<?
if(! defined('BASEPATH') ){ exit('Unable to view file.'); }
$page = $db->EscapeString($_GET['pg']);
$edit = $db->EscapeString($_GET['edit']);
$del = $db->EscapeString($_GET['del']);

if($del != "" && is_numeric($del)){$db->Query("DELETE FROM `p_pack` WHERE `id`='{$del}'");}
$pack = $db->FetchArray($db->Query("SELECT * FROM `p_pack` WHERE `id`='".$edit."'"));

if(isset($_POST['submit'])){
	$name = $db->EscapeString($_POST['name']);
	$days = $db->EscapeString($_POST['days']);
	$price = $db->EscapeString($_POST['price']);
	
	$db->Query("UPDATE `p_pack` SET `name`='".$name."', `days`='".$days."', `price`='".$price."' WHERE `id`='".$edit."'");
	$mesaj = '<div class="message success"><h3>Success!</h3><p>VIP pack successfully edited!</p></div>';
}
?>
            <div id="page-subheader">
                <div class="wrapper clearfix">
                    <nav id="sub-nav">
						<ul>
                            <li class="active"><a href="index.php?x=p_packs">Packs</a></li>
                            <li><a href="index.php?x=addpackp">Add</a></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>
        
        <section id="content">
            <div class="wrapper">
                <section class="grid_6 first top">
                    <div class="columns leading">
                        <div class="grid_6 first"><? if($edit != ""){ echo $mesaj;?>
						<form id="form" method="post" class="form widget">
                                <header><h2>Edit Pack</h2></header>
                                <section>                 
                                    <fieldset>
                                         <dl>
 											 <dt></dt><dd><label>Name</label><input type="text" name="name" value="<?=(isset($_POST['name']) ? $_POST['name'] : $pack['name'])?>" required="required" /></dd>
											 <dt></dt><dd><label>Days</label><input type="text" name="days" value="<?=(isset($_POST['days']) ? $_POST['days'] : $pack['days'])?>" required="required" /></dd>
                                             <dt></dt><dd><label>Price</label><input type="text" name="price" value="<?=(isset($_POST['price']) ? $_POST['price'] : $pack['price'])?>" required="required" /></dd>
                                        </dl>    
                                     </fieldset>
                                     <hr />
                                     <button class="button button-green" type="submit" name="submit">Submit</button>
                                     <button class="button button-gray" type="reset">Reset</button>
                                </section>
                            </form><?}else{?>
                            <table class="datatable sortable selectable paginate full">
                                <thead>
                                    <tr>
                                        <th width="25">ID</th>
                                        <th>Name</th>
                                        <th>Days</th>
                                        <th>Price</th>
										<th>Actions</th>
                                    </tr>
                                </thead>
								<tfoot>
                                    <tr>
                                        <th width="25">ID</th>
                                        <th>Name</th>
                                        <th>Days</th>
                                        <th>Price</th>
										<th>Actions</th>
                                    </tr>
                                </tfoot>
                                <tbody>
<?
  $sql = $db->Query("SELECT * FROM `p_pack` ORDER BY `id` ASC");
  for($j=1; $packs = $db->FetchArray($sql); $j++)
{
?>	
                                    <tr>
                                        <td><?=$packs['id']?></td>
                                        <td><?=$packs['name']?></td>
                                        <td><?=$packs['days']?></td>
										<td><?=$packs['price']?> $</td>
										<td><ul class="action-buttons">
                                        <li><a href="index.php?x=p_packs&edit=<?=$packs['id']?>" class="action-button" title="Edit site"><span class="pencil"></span></a></li>
										<li><a href="index.php?x=p_packs&del=<?=$packs['id']?>" class="action-button" title="Delete site"><span class="delete"></span></a></li></ul></td>
                                    </tr>
<?}?>
                                </tbody>
                            </table><?}?>
                        </div>
                    </div>

                    <div class="clear">&nbsp;</div>

                </section>

                <aside class="grid_2 top">
                    <div class="accordion">
                        <header class="current"><h2>Info</h2></header>
                        <section style="display:block">
                            Here you can manage all VIP packs!
                        </section>
                    </div>
                </aside>

                <!-- Sidebar End -->
                
                <div class="clear"></div>

            </div>
            <div id="push"></div>
        </section>

    </div>
    
    <footer id="page-footer">
        <div id="footer-inner">
            <p class="wrapper">All rights reserved &copy; <a href="http://mafianet.org" target="_blank">MafiaNet</a> <?=date('Y')?></p>
        </div>
    </footer>
</body>
</html>